*Stata version
version 18

*required packages:
*table1_mc (version 3.4)
which table1_mc
*ESTOUT (esttab version 2.1.1)
which estout
*grc1leg (version 1.0.5)
which  grc1leg


*Drop all frames
frames reset

*Navigate to folder with data (replicationdata.dta)
*cd XXXX

*Open data
use "replicationdata",clear


*log file (for some results)
capture log close
log using "main.log", replace nomsg
log off

************
**RECODING**
************

****DV******
gen arq  = q13*-1+8
lab var arq "Acceptance of reaction qualifications"

*Treatment**
gen T = Split_group
lab def Tlb 1 "Control" 2 " Involuntariness" 3 " Judgmental taste",replace
lab val T Tlb
lab var T "Treatment"

*Covariates*
codebook gender
lab def gender 1 " Female" 2 " Male", modify
codebook profile_age 
rename profile_age age
lab def profile_age 1 " 18-24" 2 " 25-34" 3 " 35-44" 4 " 45-54" 5" ≥55",modify
codebook educ_rc
lab def educ_rc 1 " (No) High-school" 2 " Some college" 3 " 4yrCollege" 4 " Post-grad",modify
rename educ_rc education
codebook race
recode race (4/8=7)
lab def race 1 " White" 2 " Black" 3 " Hispanic" 7 " Other",modify
codebook faminc_new , tab(100)
recode faminc_new (1/3 = 1 " <30K") (4/6=2 " 30-60K") (7/9=3 " 60-100K") (10/11=4 " 100-150K") (12/14=5 " 150-350K") (15/16=6 " ≥350K") (97=7 " Prefer not to say"),gen(finc)
lab var finc "Family income"
codebook q3
recode q3 (1=0 " Yes") (2=1 " No") (3=2 " Prefer not to say"),gen(tattoo)
lab var tattoo "Have Tattoo"
codebook q6
recode q6 (2=0 " Non-employer") (1=1 " Employer"),gen(employer)
lab var employer "Employer"
codebook q1
recode q1 (1=1 " Democrat") (2=3 " Republican") (3=2 " Independent") (4/5 = 4 " Other/DK/NA"),gen(partyid)
lab var partyid "Party ID"
codebook region
lab def region 1 " Northeast" 2 " Midwest" 3 " South" 4 " West",modify

*Attention
*Q1 - Involuntariness
generate Q1c = . 
replace Q1c = 1 if q12_1==1 & T==1
replace Q1c = 1 if q12_1==1 & T==3
replace Q1c = 1 if q12_1==2 & T==2

replace Q1c = 0 if q12_1==2 & T==1
replace Q1c = 0 if q12_1==1 & T==2
replace Q1c = 0 if q12_1==2 & T==3
replace Q1c = 0 if q12_1==3 

*for testing
gen Q1cT = .
replace Q1cT = 1 if q12_1==2
replace Q1cT = 0 if q12_1==1 | q12_1 ==3
replace Q1cT = . if T==3

*q12_2 - ordinary appearence
generate Q2c = . 
replace Q2c = 1 if q12_2==2 
replace Q2c = 0 if q12_2==1 
replace Q2c = 0 if q12_2==3
 
*q12_3 - judgmental 
generate Q3c = . 
replace Q3c = 1 if q12_3==2 & T==1
replace Q3c = 1 if q12_3==2 & T==2
replace Q3c = 1 if q12_3==1 & T==3

replace Q3c = 0 if q12_3==1 & T==1
replace Q3c = 0 if q12_3==1 & T==2
replace Q3c = 0 if q12_3==2 & T==3
replace Q3c = 0 if q12_3==3 

*for testing
gen Q3cT = .
replace Q3cT = 1 if q12_3==1
replace Q3cT = 0 if q12_3==2 | q12_3 ==3
replace Q3cT = . if T==2

 
*q12_4 - interaction w/ costumers
generate Q4c = . 
replace Q4c = 1 if q12_4==1
replace Q4c = 0 if q12_4==2
replace Q4c = 0 if q12_4==3 

*All correct
gen QAc = .
replace QAc = 1 if Q1c == 1 & Q2c == 1 & Q3c == 1 & Q4c == 1
replace QAc = 0 if Q1c == 0 | Q2c == 0 | Q3c == 0 | Q4c == 0
*2 main correct
gen Qa2c = .
replace Qa2c = 1 if Q1c == 1 & Q3c == 1
replace Qa2c = 0 if Q1c == 0 | Q3c == 0 

*AVG CORRECT
egen avgcor = rowtotal(Q1c Q2c Q3c Q4c)
***************
frame put *, into(full)


***************************
***********ANALYSES********
***************************

**Attention**
log on
*average correct
su avgcor 

*Table A2
su Q1c Q2c Q3c Q4c

*Table A3
ta q12_1 T,col
ta q12_2 T,col
ta q12_3 T,col
ta q12_4 T,col

*Correct involuntary vs. control
prtest Q1cT if T<3, by(T)
*Correct judgmental vs. control
prtest Q3cT if T!=2, by(T)
log off


*****Table S4/balance*******
table1_mc, by(T) vars(gender cat \age cat\education cat\race cat\ finc cat \region cat\ employer cat\ partyid cat\ tattoo cat)  onecol saving(balance.xlsx,replace)


****main results***
eststo clear
*M1
reg arq i.T
loc Nm1 = e(N)
mat B1 = r(table)
eststo m1
margins, at(T=(1 2 3)) post
mat B2 = r(table)
mat A = 1,3.1, B2[1,1], B2[5,1], B2[6,1], 0,.,. \1,2.1, B2[1,2], B2[5,2], B2[6,2], B1[1,2],B1[5,2],B1[6,2]\1,1.1, B2[1,3], B2[5,3], B2[6,3],B1[1,3],B1[5,3],B1[6,3]

*M2
reg arq i.T i.gender i.age i.education i.race i.finc i.region i.employer i.partyid i.tattoo
eststo m2
mat B1 = r(table)
margins, at(T=(1 2 3)) post
mat B2 = r(table)
mat A = A\2,3.0, B2[1,1], B2[5,1], B2[6,1], 0,.,. \2,2.0, B2[1,2], B2[5,2], B2[6,2], B1[1,2],B1[5,2],B1[6,2]\2,1.0, B2[1,3], B2[5,3], B2[6,3],B1[1,3],B1[5,3],B1[6,3]

*M3
reg arq i.T if Qa2c ==1
loc Nm3 = e(N)
mat B1 = r(table)
eststo m3
margins, at(T=(1 2 3)) post
mat B2 = r(table)
mat A = A\3,2.9, B2[1,1], B2[5,1], B2[6,1], 0,.,. \3,1.9, B2[1,2], B2[5,2], B2[6,2], B1[1,2],B1[5,2],B1[6,2]\3,0.9, B2[1,3], B2[5,3], B2[6,3],B1[1,3],B1[5,3],B1[6,3]

***Table 2**
esttab m1 m2 m3 using"tab1",label  ///
refcat(2.T "Treatment (Ref: Control)" 2.gender "Gender (Ref: Female)" ///
2.education "Education (Ref: Highschool or below)" 2.race "Race (Ref: White)" 2.age "Age (Ref: 18-24)" ///
2.finc "Family Income (Ref: <30K)" 2.region "Region (Ref: Northeast)" 1.employer "Employer (Ref: No)" ///
1.tattoo "Have tattoo (Ref: Yes)" 2.partyid "PartyID (Ref: Democrat)",nolab) ///
nobaselevels mlabels(,none) mtitles(,none) collabels(,none)	varwidth(0) rtf replace ///
 wide  notes b(2) compress onecell

 
*interactions 
foreach	var in gender age education race finc region employer partyid tattoo {
reg arq i.T i.T#`var'  i.gender i.age i.education i.race i.finc i.region i.employer i.partyid i.tattoo
}

*Interaction Tables* (Tables S5-S13)
*gender
eststo clear
reg arq i.T i.T#gender  i.gender i.age i.education i.race i.finc i.region i.employer i.partyid i.tattoo
eststo 
esttab using"tabA5_gender", keep(2.T 3.T 2.gender 2.T#2.gender 3.T#2.gender) label varwidth(39) ///
refcat(2.T "Treatment (Ref: Control)" 2.T#2.gender "Interaction (Ref: Control # Female)" 2.gender "Gender (Ref: Female)",nolab) ///
order(2.T 3.T 2.gender) ///
nobaselevels mlabels(,none) mtitles(,none) collabels(,none) rtf replace ///
 wide  notes b(2) compress onecell
 
*age
eststo clear
reg arq i.T i.T#age  i.gender i.age i.education i.race i.finc i.region i.employer i.partyid i.tattoo
eststo 
esttab using"tabA5_age", keep(2.T 3.T 2.age 3.age 4.age 5.age ///
2.T#2.age 2.T#3.age 2.T#4.age 2.T#5.age 3.T#2.age 3.T#3.age 3.T#4.age 3.T#5.age) label varwidth(39) ///
refcat(2.T "Treatment (Ref: Control)" 2.T#2.age "Interaction (Ref: Control # 18-24)" 2.age "Age (Ref: 18-24)",nolab) ///
order(2.T 3.T 2.age 3.age 4.age 5.age) ///
nobaselevels mlabels(,none) mtitles(,none) collabels(,none) rtf replace ///
 wide  notes b(2) compress onecell

*education
eststo clear
reg arq i.T i.T#education  i.gender i.age i.education i.race i.finc i.region i.employer i.partyid i.tattoo
eststo 
esttab using"tabA5_education", keep(2.T 3.T 2.education 3.education 4.education ///
2.T#2.education 2.T#3.education 2.T#4.education 3.T#2.education 3.T#3.education 3.T#4.education) label varwidth(39) ///
refcat(2.T "Treatment (Ref: Control)" 2.T#2.education "Interaction (Ref: Control # HS or below)" 2.education "Education (Ref: HS or below)",nolab) ///
order(2.T 3.T 2.education 3.education 4.education) ///
nobaselevels mlabels(,none) mtitles(,none) collabels(,none) rtf replace ///
 wide  notes b(2) compress onecell
 
 
*race
eststo clear
reg arq i.T i.T#race  i.gender i.age i.education i.race i.finc i.region i.employer i.partyid i.tattoo
eststo 
esttab using"tabA5_race", keep(2.T 3.T 2.race 3.race 7.race ///
2.T#2.race 2.T#3.race 2.T#7.race 3.T#2.race 3.T#3.race 3.T#7.race) label varwidth(39) ///
refcat(2.T "Treatment (Ref: Control)" 2.T#2.race "Interaction (Ref: Control # White)" 2.race "Race (Ref: White)",nolab) ///
order(2.T 3.T 2.race 3.race 7.race) ///
nobaselevels mlabels(,none) mtitles(,none) collabels(,none) rtf replace ///
 wide  notes b(2) compress onecell
 
*income
eststo clear
reg arq i.T i.T#finc  i.gender i.age i.education i.race i.finc i.region i.employer i.partyid i.tattoo
eststo 
esttab using"tabA5_income", keep(2.T 3.T 2.finc 3.finc 4.finc 5.finc 6.finc 7.finc ///
2.T#2.finc 2.T#3.finc 2.T#4.finc 2.T#5.finc 2.T#6.finc 2.T#7.finc 3.T#2.finc 3.T#3.finc 3.T#4.finc 3.T#5.finc 3.T#6.finc 3.T#7.finc) ///
label varwidth(39) ///
refcat(2.T "Treatment (Ref: Control)" 2.T#2.finc "Interaction (Ref: Control # <30K)" 2.finc "Family Income (Ref: <30K)",nolab) ///
order(2.T 3.T 2.finc 3.finc 4.finc 5.finc 6.finc 7.finc) ///
nobaselevels mlabels(,none) mtitles(,none) collabels(,none) rtf replace ///
 wide  notes b(2) compress onecell 
 

*region
eststo clear
reg arq i.T i.T#region  i.gender i.age i.education i.race i.finc i.region i.employer i.partyid i.tattoo
eststo 
esttab using"tabA5_region", keep(2.T 3.T 2.region 3.region 4.region ///
2.T#2.region 2.T#3.region 2.T#4.region 3.T#2.region 3.T#3.region 3.T#4.region) label varwidth(39) ///
refcat(2.T "Treatment (Ref: Control)" 2.T#2.region "Interaction (Ref: Control # Northeast)" 2.region "Region (Ref: Northeast)",nolab) ///
order(2.T 3.T 2.region 3.region 4.region) ///
nobaselevels mlabels(,none) mtitles(,none) collabels(,none) rtf replace ///
 wide  notes b(2) compress onecell

*employer
eststo clear
reg arq i.T i.T#employer  i.gender i.age i.education i.race i.finc i.region i.employer i.partyid i.tattoo
eststo 
esttab using"tabA5_employer", keep(2.T 3.T 1.employer 2.T#1.employer 3.T#1.employer) label varwidth(39) ///
refcat(2.T "Treatment (Ref: Control)" 2.T#1.employer "Interaction (Ref: Control # No)" 1.employer "Employer (Ref: No)",nolab) ///
order(2.T 3.T 1.employer) ///
nobaselevels mlabels(,none) mtitles(,none) collabels(,none) rtf replace ///
 wide  notes b(2) compress onecell

*polid
eststo clear
reg arq i.T i.T#partyid  i.gender i.age i.education i.race i.finc i.region i.employer i.partyid i.tattoo
eststo 
esttab using"tabA5_partyid", keep(2.T 3.T 2.partyid 3.partyid 4.partyid ///
2.T#2.partyid 2.T#3.partyid 2.T#4.partyid 3.T#2.partyid 3.T#3.partyid 3.T#4.partyid) label varwidth(39) ///
refcat(2.T "Treatment (Ref: Control)" 2.T#2.partyid "Interaction (Ref: Control # Democrat)" 2.partyid "PartyID (Ref: Democrat)",nolab) ///
order(2.T 3.T 2.partyid 3.partyid 4.partyid) ///
nobaselevels mlabels(,none) mtitles(,none) collabels(,none) rtf replace ///
 wide  notes b(2) compress onecell
 
*tattoo
eststo clear
reg arq i.T i.T#tattoo  i.gender i.age i.education i.race i.finc i.region i.employer i.partyid i.tattoo
eststo 
esttab using"tabA5_tattoo", keep(2.T 3.T 1.tattoo 2.tattoo 2.T#1.tattoo 2.T#2.tattoo 3.T#1.tattoo 3.T#2.tattoo) label varwidth(39) ///
refcat(2.T "Treatment (Ref: Control)" 2.T#1.tattoo "Interaction (Ref: Control # Yes)" 1.tattoo "Have tattoo (Ref: Yes)",nolab) ///
order(2.T 3.T 1.tattoo 2.tattoo) ///
nobaselevels mlabels(,none) mtitles(,none) collabels(,none) rtf replace ///
 wide  notes b(2) compress onecell
 
 
*Results for figure 2
*partyid
reg arq i.T##partyid  i.gender i.age i.education i.race i.finc i.region i.employer  i.tattoo
margins, dydx(T) at(partyid=(1 2 3 4)) 
mat DYDX = r(table)
mat F2 = ///
2,4.1, DYDX[1,5],DYDX[5,5],DYDX[6,5]\ ///
3,3.9, DYDX[1,9],DYDX[5,9],DYDX[6,9]\ ///
2,3.1, DYDX[1,6],DYDX[5,6],DYDX[6,6]\ ///
3,2.9, DYDX[1,10],DYDX[5,10],DYDX[6,10]\ ///
2,2.1, DYDX[1,7],DYDX[5,7],DYDX[6,7]\ ///
3,1.9, DYDX[1,11],DYDX[5,11],DYDX[6,11]\ ///
2,1.1, DYDX[1,8],DYDX[5,8],DYDX[6,8]\ ///
3,0.9, DYDX[1,12],DYDX[5,12],DYDX[6,12]




***FIGURES***

*Figure 1
clear
svmat A

su A4
loc Lmin = r(min)
su A5
loc Lmax = r(max)
su A7
loc Dmin = r(min)
su A8
loc Dmax = r(max)


tw ///
(rspike A4 A5 A2, horizontal) ///
(scatter A2 A3 if A1 ==1, ms(O) mcolor(black)) ///
(scatter A2 A3 if A1 ==2) ///
(scatter A2 A3 if A1 ==3) ///
,name(level,replace) ///
ylabel(1 "Judgmental taste" 2 "Involuntariness" 3 "Control", nogrid notick) ytit("") ///
yscale(range(0.8 2.2)) ytick(0.8 3.2, notick) ///
xtit("Average acceptance of relying on reaction qualifications (1-7)") ///
xlab(3.2 (0.2) 4.2, format(%2.1f)) xtick(`Lmin' `Lmax',notick) ///
 graphregion(margin(-3 2 0 0)) ///
 legend(pos(6) label(2 "M1: Bivariate") label(3 "M2: W/ covariates") label(4 "M3: W/O inattentive resp.") label(1 "95% Confidence interval") order(2 3 4 1) row(1) size(vsmall)) fxsize(106)
 
tw ///
(rspike A7 A8 A2 if A2 <2.5, horizontal) ///
(scatter A2 A6 if A1 ==1, ms(O) mcolor(black)) ///
(scatter A2 A6 if A1 ==2) ///
(scatter A2 A6 if A1 ==3) ///
 , name(diff,replace)  xline(0) ylab(none) ytit("") yscale(off) ///
 xtit("Average treatment effect (cf. Control)") ///
 xlab(-.8 (0.2) 0.4) xtick(`Dmin' `Dmax',notick) ///
 graphregion(margin(2 0 0 0)) ///
 legend(pos(6) row(1))
 
grc1leg level diff,row(1) ycommon  graphregion(margin(0 0 0 -5))  legendfrom(level) pos(6)  name(comb,replace)
gr display comb, ysize(3)
graph export "fig1.pdf", replace
capture putpdf clear  
putpdf begin
putpdf paragraph
putpdf text ("Notes: N = `Nm1' (Model 1-2)/`Nm3' (Model 3). See Table 2 for the full results and the list of covariates in Model 2. All covariates are held at their observed values when calculating the predicted level of acceptance based on Model 2.") 
putpdf save "Fig1_notes.pdf", replace


***Fig 2
clear
mat A = F2
svmat A

su A4
loc Lmin = r(min)
su A5
loc Lmax = r(max)
tw ///
(rspike A4 A5 A2, horizontal) ///
(scatter A2 A3 if A1 ==2, ms(O) mcolor(black)) ///
(scatter A2 A3 if A1 ==3) ///
,name(dydx,replace) ///
ylabel(1 "Other/DK/NA" 2 "Republican" 3 "Independent" 4 "Democrat", nogrid notick) ytit("") ///
xtit("Average treatment effect (cf. Control)") ///
yscale(range(0.8 4.2)) ytick(0.8 4.2, notick) ///
xlab(-0.5 (0.5) 1.5, format(%2.1f)) xtick(`Lmin' `Lmax',notick) ///
xline(0) ///
 graphregion(margin(0 0 0 -5)) ///
 legend(pos(6) label(2 "Involuntariness") label(3 "Judgmental taste") label(1 "95% Confidence interval") order(2 3  1) row(1) size(vsmall)) ysize(2.5)

graph export "fig2.pdf", replace 
putpdf begin
putpdf paragraph
putpdf text ("Notes: N = `Nm1'; Results are based on a model with the same specification as Model 2 in Table 2, but including an interaction term between treatment status and party identification. See Table S12 in the SI for the full results. DK signify 'Don't know' and NA signify 'Prefer not to say'.") 
putpdf save "Fig2_notes.pdf", replace


*Histogram/S1
frame copy full temp,replace
cwf temp
twoway__histogram_gen arq if T==1,gen(h1 x1) discrete percent
twoway__histogram_gen arq if T==2,gen(h2 x2) discrete percent
twoway__histogram_gen arq if T==3,gen(h3 x3) discrete percent

count if T==1
loc t1 = r(N)
count if T==2
loc t2 = r(N)
count if T==3
loc t3 = r(N)



keep x1-h3
keep in 1/7
rename x1 x
drop x2 x3
 reshape long h , i(x) j(T)
 replace x = x-0.2 if T==1
 replace x = x+0.2 if T==3
 
 tw ///
(bar h x if T==1,barw(0.2)) ///
(bar h x if T==2,barw(0.2)) ///
(bar h x if T==3,barw(0.2)) ///
 , ylab(0 (5) 25) ///
 xlab(1 (1) 7) ///
 ytit(Within group percent) ///
 xtick(0.7 7.3,notick) ///
 legend(pos(6) row(1) label (1 "Control (N= `t1')") label(2 "Involuntariness (N= `t2')") label (3 "Judgmental taste (N= `t3')")) ///
 graphregion(margin(0 0 0 0))
 graph export "hist.pdf", replace 

 
frame copy full temp,replace
cwf temp
reg arq i.T

log on 
***power/MDE**
*involuntary
ttest arq if T!=3,by(T)
*MDE:
di  r(se)*2.8
*MDE in Cohens D:
di  (r(se)*2.8)/r(sd)
*judgmental t
ttest arq if T!=2,by(T)
*MDE:
di  r(se)*2.8
*MDE in Cohens D:
di  (r(se)*2.8)/r(sd)

*cleaning up
log off 
log close
frames reset
exit
